﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WXYW.BLL;

namespace WXYW
{
    public partial class ListApplicationProductByProductType : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindProduct();
            }
        }

        private void BindProduct()
        {
            ApplicationProductService service = new ApplicationProductService();
            productGridView.DataSource = service.GetProductByProductType(long.Parse(Request.QueryString[Constants.QUERYSTR_PRODUCTTYPE_ID]));
            productGridView.DataBind();
        }

        protected void productGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            if (e.NewPageIndex >= 0 && e.NewPageIndex < productGridView.PageCount)
            {
                productGridView.PageIndex = e.NewPageIndex;
            }
            
            BindProduct();
        }

        protected void productGridView_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.DataItem != null)
            {
                e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#FFFF99'");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
                ((Label)e.Row.FindControl("IDLbl")).Text = (e.Row.RowIndex + 1).ToString();
            }
        }

        protected void viewLinkButton_Click(object sender, EventArgs e)
        {
            string productID = ((LinkButton)sender).CommandArgument;
            Response.Redirect(string.Format("MaintainRecordDetail.aspx?{0}={1}", Constants.QUERYSTR_PRODUCT_ID, productID));
        }
    }
}
